<?php
    require_once "config.php";
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $date = array(
            'nickname'      => $_POST['nickname'],
            'bank_add'      => $_POST['bank_add'],
            'mobile'      => $_POST['mobile'],
            'sale_id'      => $_POST['sale_id'],
            'bank'      => $_POST['bank'],
            'money'      => $_POST['money'],
        );
        $sale_sql = $mysql->query('select * from dyspw_salesman where id = '.$date['sale_id']);
        $sale = $sale_sql->fetch_all(MYSQLI_ASSOC);
        if(empty($sale)){
            $result['status'] = 'n';
            $result['info'] = '未查询到此业务员信息';
            exit(json_encode($result));
        }
        if($date['money'] > $sale[0]['cash']){
            $result['status'] = 'n';
            $result['info'] = '提现金额大于可提现金额';
            exit(json_encode($result));
        }
        $time = time();
        $info = '现金提取'.$date['money'].'元';
        $cash_add = $mysql->query("INSERT INTO dyspw_salesman_extract (s_id, s_name, s_avatar, nickname, bank_add, mobile, bank_num, `money`, launch_time,info) VALUES ({$sale[0]['id']},'{$sale[0]['u_name']}','{$sale[0]['u_avatar']}','{$date['nickname']}','{$date['bank_add']}','{$date['mobile']}','{$date['bank']}','{$date['money']}',$time,'{$info}')");
        if($cash_add){
            $mysql->query("UPDATE dyspw_salesman SET cash = cash-{$date['money']} WHERE `id`={$sale[0]['id']}");
            $result['status'] = 'y';
            $result['info'] = '提现申请成功，请等待审核';
            exit(json_encode($result));
        }else{
            $result['status'] = 'n';
            $result['info'] = '提现申请提交失败，请重新提交';
            exit(json_encode($result));
        }
    }
 ?>
